package StudentSerlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/serletStudent")
public class serletStudent extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String usename = req.getParameter("usename");
        String age = req.getParameter("age");
        String cj = req.getParameter("cj");

        BufferedWriter bw =new BufferedWriter(new FileWriter("d:stu.txt\\",true));
        bw.write(usename+","+age+","+cj);
        bw.newLine();
        bw.close();

        PrintWriter writer = resp.getWriter();
        writer.println("Save");
        writer.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
